class Solution
{
public:
    int maxNumOfMarkedIndices(vector<int> &nums)
    {
        sort(nums.begin(), nums.end());
        int n = nums.size();
        vector<int> consumeFlag(n, 0);
        int continuousConsumed = 0;
        int result = 0;
        for (int i = 0; i < n; ++i)
        {
            if (consumeFlag[i])
            {
                int toChangeConsume = max(i, continuousConsumed) + 1;
                while (toChangeConsume < n && consumeFlag[toChangeConsume])
                {
                    ++toChangeConsume;
                }
                if (toChangeConsume >= n)
                {
                    break;
                }
                consumeFlag[toChangeConsume] = 1;
                continuousConsumed = toChangeConsume;
            }
            int toConsume = lower_bound(nums.begin(), nums.end(), 2 * nums[i]) - nums.begin();
            if (toConsume == n)
            {
                break;
            }
            if (consumeFlag[toConsume])
            {
                int toChangeConsume = max(toConsume, continuousConsumed) + 1;
                while (toChangeConsume < n && consumeFlag[toChangeConsume])
                {
                    ++toChangeConsume;
                }
                if (toChangeConsume >= n)
                {
                    break;
                }
                consumeFlag[toChangeConsume] = 1;
                // continuousConsumed = toChangeConsume;
            }
            else
            {
                consumeFlag[toConsume] = 1;
            }
            result += 2;
        }
        return result;
    }
};